<?php
namespace Api\Controller;
use Think\Controller;
class UserIfoController extends CommonController {
	public function _initialize(){
		
		parent::_initialize();
	}
	
    public function check(){
        $id = I('get.id');
        
        $Userifo = M('Userifo');
        
        if($id == ''){
			$this->response( false , 2 , '没有数据' , false);
		}
		else{
			$list = $Userifo->where("user_id={$id}")->find();
        
			if( $list == false){
				$this->response( false , 1 , '没有数据' , true);
			}
			$this->response( true , 0 , $list , true);
		}
        
		
    }
    //个人信息添加或修改
    public function insert()
    {
		//获取信息
		$id			= I('get.id');
		$nickname	= I('get.nickname');
		$name		= I('get.name');
		$sex		= I('get.sex');
		$year		= I('get.year');
		$month		= I('get.month');
		$day		= I('get.day');
		$telephone	= I('get.telephone');
		$email		= I('get.email');
		
		$Userifo = M('Userifo');
		
		$res = $Userifo->where("user_id={$id}")->find();
		$list=$Userifo->create();
		if( $res == false){
			$data =array(
			'nickname'	=>	$nickname,
			'name'		=>	$name,
			'sex'		=>	$sex,
			'year'		=>	$year,
			'month'		=>	$month,
			'day'		=>	$day,
			'telephone'	=>	$telephone,
			'email'		=>	$email,
			'user_id'	=>	$id
			);
			$list = $Userifo->add($data);//添加成功
		}
		else{
			$data =array(
			'nickname'	=>	$nickname,
			'name'		=>	$name,
			'sex'		=>	$sex,
			'year'		=>	$year,
			'month'		=>	$month,
			'day'		=>	$day,
			'telephone'	=>	$telephone,
			'email'		=>	$email,
			);
			$list = $Userifo->where("user_id={$id}")->save($data);//修改成功
		}
		
		
		$this->response( true , 0 , '修改成功' , true);
	}
	
	
}
